<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background: yellow;
            position: absolute;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        var oBox=document.querySelector(".box");
        oBox.onmousedown=function(evt){
            var e=evt||window.event;
            var disX=e.pageX-this.offsetLeft;
            var disY=e.pageY-this.offsetTop;
            document.onmousemove=function(evt){
                var e=evt||window.event;
                oBox.style.left=e.pageX-disX+"px";
                oBox.style.top=e.pageY-disY+"px";
            }
            document.onmouseup=function(){
                document.onmousemove=document.onmouseup=null;
            }
        }
    </script>
</body>
</html>